﻿using System.Collections.Generic;
using Entitas;
class EnemyResetRoamingAngleSystem : ReactiveSystem<EnemyEntity>
{
    
    public EnemyResetRoamingAngleSystem(Contexts contexts)  : base(contexts.enemy) 
    {
        
    }

    protected override void Execute(List<EnemyEntity> entities)
    {
       
        foreach(var e in entities)
        {
            var rand = new System.Random();
            if (e.roamingTimer.value < 0)
            {
                e.ReplaceRoamingAngle(rand.Next(1, 359));
            }
        }
    }

    protected override bool Filter(EnemyEntity entity)
    {
       return entity.isRoaming==true&&entity.hasRoamingTimer && entity.hasRoamingAngle;
    }

    protected override ICollector<EnemyEntity> GetTrigger(IContext<EnemyEntity> context)
    {
        return context.CreateCollector(EnemyMatcher.RoamingTimer.AddedOrRemoved());
    }
}

